import vnode from "./vnode";
/**
 * h函数
 * @param sel
 * @param data
 * @param c
 */
export default function (sel, data, c) {
    if(arguments.length !== 3) {
        throw new Error('h函数必须是三个参数')
    }
    if (typeof c === 'string' || typeof c === 'number') {
        return vnode(sel, data, undefined, c, undefined);
    }
    if (typeof c === 'object' && c.hasOwnProperty('sel')) {
        const children = [c];
        return vnode(sel, data, children, undefined, undefined )

    }
    if (Array.isArray(c)) {
        const children = [];
        for (let i = 0; i < c.length; i ++) {
            if (typeof c[i] === 'object' && c[i].hasOwnProperty('sel')) {
                throw new Error('数组中存在非h()参数项')
            }
            children.push(c[i]);
            return vnode(sel, data, children, undefined, undefined);
        }
    }
    throw new Error('参数类型不对');
}
